package ltu.m7011e.server.service.impl;

import java.util.Date;

public class DateCalc {
    
	
	public String getDateDifference(Date linkDate){
		String result = null;
		Date today = new Date(); 
		
		 long diffSeconds;
		 long diffMinutes;
		 long diffHours;
		 long diffDays;
		 long diffMonths;
		
		 long linkDateMilliseconds = linkDate.getTime();
		 long todayMilliseconds = today.getTime();
		
		 long diff = todayMilliseconds - linkDateMilliseconds ;
		 
		 diffSeconds = diff / 1000;
		 diffMinutes = diffSeconds / 60;
		 diffHours = diffMinutes / 60;
		 diffDays = diffHours / 24;
		 diffMonths = diffDays / 30;
		 
		 if (diffMonths > 0){
			result = (diffMonths+" Month");
		 }	else { if (diffDays > 0)
		 	{
			result = (diffDays + " Day");
			diff = diffDays;	
		 	}
		 		else {if (diffHours > 0)
		 		{
				result = (diffHours + " Hour");
		 		diff = diffHours;
		 		}
					else {if (diffMinutes > 0)
					{
					result = (diffMinutes + " Minute");
					diff = diffMinutes;
					}
						else {if (diffSeconds > 0)
						{
						result = (diffSeconds + " Second");
						diff = diffSeconds;
						}
						
							}
						} 
					} 
		 		}
		 
		 if (result == null)
			 result = "0 Second";
		 
		 if (diff == 1)
			 result = result + " ago";
		 else
			 result = result + "s ago";
		 
		 //System.out.println(result);
		 
		
		return result;
	}
}
